package com.wutianyi.favority.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.wutianyi.favority.FavorityRepository;
import com.wutianyi.favority.bean.User;
import com.wutianyi.favority.service.FavorityServiceLocator;
import com.wutianyi.favority.utils.FavorityUtils;

public class DeleteFolderServlet extends HttpServlet {

	/**
     * 
     */
	private static final long serialVersionUID = 8539601061933113144L;

	private static FavorityRepository repository = FavorityServiceLocator
			.getRepository();

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {

		req.setCharacterEncoding("utf-8");
		resp.setCharacterEncoding("utf-8");

		long folderId = FavorityUtils.stringToLong(
				req.getParameter("folderId"), -1);
		long uid = FavorityUtils.stringToLong(req.getParameter("uid"), -1);

		if (-1 != folderId && -1 != uid) {
			User user = repository.getUser(uid);
			if (null != user) {
				int r = user.removeFolder(folderId);
				if (1 == r) {
					req.setAttribute("result", "删除成功");
				}
			}
		}
		req.setAttribute("uid", uid);
		resp.sendRedirect("index?uid=" + uid);
	}

}
